package com.woniuxy.educationplatform.controller;

import com.woniuxy.educationplatform.bean.*;
import com.woniuxy.educationplatform.service.IVideoService;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/video")
public class VideoController {

    @Resource
    private IVideoService videoServiceImpl;

    @RequestMapping("/findAll")
    public List<VideoBean> findAll(){
        System.out.println("开始查询所有视频");
        return videoServiceImpl.findAll();
    }

    @RequestMapping("/more")
    public void saveVideoBean(String videoName, Long pid, Long sid, Long cid, Long tid, Long kid, String createTime){
        System.out.println("开始上传视频地址");
        System.out.println(videoName);
        System.out.println(pid);
        System.out.println(sid);
        System.out.println(cid);
        System.out.println(tid);
        System.out.println(kid);
        System.out.println(createTime);
        VideoBean videoBean=new VideoBean();
        ProjectBean projectBean=new ProjectBean();
        SubjectBean subjectBean=new SubjectBean();
        CourseBean courseBean=new CourseBean();
        TeacherBean teacherBean=new TeacherBean();
        KnowpointBean knowpointBean=new KnowpointBean();
        projectBean.setId(pid);
        subjectBean.setId(sid);
        courseBean.setId(cid);
        teacherBean.setId(tid);
        knowpointBean.setId(kid);
        videoBean.setVideoName(videoName);
        videoBean.setProjectBean(projectBean);
        videoBean.setSubjectBean(subjectBean);
        videoBean.setCourseBean(courseBean);
        videoBean.setTeacherBean(teacherBean);
        videoBean.setKnowpointBean(knowpointBean);
        String no="v"+createTime;
        videoBean.setVideoNo(no);
        videoServiceImpl.saveVideoBean(videoBean);
        System.out.println(videoBean);
    }

    @RequestMapping("find")
    public List<VideoBean> find(String videoName,@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date createTime){
        System.out.println("开始条件查询");
        System.out.println(videoName);
        System.out.println(createTime);
        VideoBean videoBean=new VideoBean();
        videoBean.setCreateTime(createTime);
        videoBean.setVideoName(videoName);
        return videoServiceImpl.findOneByCondition(videoBean);

    }
    @RequestMapping("/change")
    public void change(String videoName,Long id){
        System.out.println("开始修改");
        System.out.println(videoName);
        System.out.println(id);
        VideoBean videoBean=new VideoBean();
        videoBean.setVideoName(videoName);
        videoBean.setId(id);
        videoServiceImpl.update(videoBean);
        System.out.println("完成修改");
    }

    @RequestMapping("/del")
    public void del(Long id){
        System.out.println("开始删除程序");
        System.out.println(id);
        videoServiceImpl.deleteVideoBean(id);
        System.out.println("完成删除");
    }
}
